package com.weiyuwqj.server.mapper;

import com.weiyuwqj.api.model.BasItemPrepayment;
import com.weiyuwqj.api.model.BusItemRepay;
import com.weiyuwqj.api.model.vo.AccountCheckingVo;
import com.weiyuwqj.api.model.vo.BusItemRepayVo;
import com.weiyuwqj.api.model.vo.ItemRepayOrderVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Repository
public interface BusItemRepayMapper extends Mapper<BusItemRepay> {

    //显示&查询
    List<BusItemRepayVo> getList(Map<String, Object> param);

    //单个repay
    BusItemRepay getRepayListByItemIdAndCurrentPeriod(Integer itemId, Integer currentPeriod);

    //全部repay
    List<BusItemRepay> getRepayListsByItemIdAndCurrentPeriod(Integer itemId);

    int updateRepayStatus(BusItemRepay repay);

    //统计已还款的资金
    Double sumByRepayItemAccount(Map map);

    //统计未还款资金
    Double sumByNoRepayItemAccount(Map map);

    //统计已还款笔数
    Integer countByRepayItemNum(Map map);

    //统计已还款的利息
    Double sumByRepayItemInterest(Map map);

    //统计未还款笔数
    Integer countByNoRepayItemNum(Map map);

    //统计未还款利息总额
    Double sumByNoRepayItemInterest(Map map);

    BigDecimal sumRepayAccount(Map map);

    List getRepayList(Map map);

    //查询当天应还项目的记录
    List<BusItemRepay> getListByToDay();

    Map statRepay(Map<String, Object> map);

    Map statNoRepay(Map<String, Object> map);

    //还款根据订单号查询信息
    ItemRepayOrderVo getOneByOrderNo(String repayOrder);

    //根据id和状态修改数据
    Integer updateRepayByStatusAndId(Map map);

    //根据项目id查询单条记录
    BusItemRepay getRepayByItemId(@Param("itemId") Integer itemId);

    //根据itemId查询已完成并且最新的一条数据
    BusItemRepay getLastRepayByItemId(Integer itemId);

    //根据itemId和期数删除数据
    Integer deleteByItemId(@Param("itemId") Integer itemId,@Param("repayCurrentPeriod") Integer repayCurrentPeriod);

    //根据项目id和期数修改数据
    Integer modifyRepayByItemIdAndUserId(Map map);

    //查询已经还款的期数
    List<BusItemRepay> listRepayedRepay(Map map);

    //查询未还款的期数
    List<BusItemRepay> listNoRepayedRepay(Map map);

    //查询最后一期待还记录
    BusItemRepay selectPrincipalByItemIdAndUserId(@Param("itemId")Integer itemId,@Param("userId")Integer userId);

	/**
	 * 获取收益金额
	 *
	 * @param itemId 项目ID
	 * @return 收益金额
	 */
	BigDecimal getRepayIncome(@Param("itemId") Integer itemId);

	/**
	 * 回款日期
	 *
	 * @param itemId 项目ID
	 * @return 回款日期
	 */
	Date getRepayEndDate(@Param("itemId") Integer itemId);

    AccountCheckingVo getStatByItemId(Integer itemId);

    //对账管理列表统计
    Map checkAccountStat(Map map);

    //对账管理根据项目id获取还款计划
    List<BusItemRepay> getRepayListByItemId(Integer itemId);

    //根据项目id统计还款计划
    Map statRepayByItemId(Integer itemId);
}